<?php
class galleria extends CI_Controls{

	public $show_num_images;
	public $images;
	public $videos;
	public $thumbs;
	public $big_images;
	public $titles;
	public $descriptions;
	public $dummy='/images/noimage.jpg';
	public $transition='slide';
	public $autoplay=true;
	public $transition_speed=400;
	public $theme;
	/*pa videos mirar:
	 * http://galleria.io/docs/getting_started/quick_start/
	*
	* */

	/**
	 * http://galleria.io/docs/api/methods/ (recargar con nuevas imagenes)
	 * galleria.io/docs/1.2/options
	 * @var unknown_type
	 */
	public $options='';
	public $image_crop=false;
	function __construct(){
		parent::__construct();
		$this->theme=galleria::THEME_CLASSIC;
	}


	/*  temas   */
	const THEME_CLASSIC='classic';
	const THEME_TWELVE='twelve';
	private $temas= array(
			'classic'=>array(
					'js'	=>'js/vendor/galleria/themes/classic/galleria.classic.min.js',
					'css'	=>'js/vendor/galleria/themes/classic/galleria.classic.css'
			),
			'twelve'=>array(
					'js'	=>'js/vendor/galleria/themes/twelve/galleria.twelve.min.js',
					'css'	=>'js/vendor/galleria/themes/twelve/galleria.twelve.css'
			)
	);

	function drawContent(){

		//echo $this->autoplay;
		//$this->dummy=$this->load_img('classic-loader.gif');
		$div= new div();
		$div->atributos=$this->atributos;

		if(is_bool($this->image_crop)){
			if($this->image_crop==true)
				$this->image_crop="true";
			else
				$this->image_crop="false";
		}
		$this->galleriaScript();
		return  $div;

	}

	private function galleriaScript(){
		

		$this->autoplay=$this->autoplay? 'true': 'false';
		$i=0;
		$dataJS['images']='';
		$nimg=count($this->images);
		for(;$i<$nimg;++$i)
		{

			$dataJS['images'].='{ image: "'.$this->images[$i].'"';
			if(!empty($this->thumbs[$i])){
				$dataJS['images'].=', thumb: "'.$this->thumbs[$i].'"';
			}
			if(!empty($this->big_images[$i])){
				$dataJS['images'].=', big: "'.$this->big_images[$i].'"';
			}
			if(!empty($this->titles[$i])){
				$dataJS['images'].=' ,title: "'.$this->titles[$i].'"';
			}
			if(!empty($this->descriptions[$i])){
				$dataJS['images'].=', description: "'.$this->descriptions[$i].'"';
			}
			$dataJS['images'].=' },';

		}

		$dataJS['videos']='';
		$i=0;
		$nvid=count($this->videos);
		for(;$i<$nvid;++$i)
		{

			$dataJS['videos'].='{ video: "'.$this->videos[$i].'"';
			if(!empty($this->titles[$i])){
				$dataJS['videos'].=' ,title: "'.$this->titles[$i].'"';
			}
			if(!empty($this->descriptions[$i])){
				$dataJS['videos'].=', description: "'.$this->descriptions[$i].'"';
			}
			$dataJS['videos'].=' },';

		}

		$elementos=$dataJS['videos'].$dataJS['images'];

		$this->CI->dynamic_assets->add_js(base_url('js/vendor/galleria/galleria-1.3.5.min.js'));
		$this->CI->dynamic_assets->add_css(base_url($this->temas[$this->theme]['css']));
		
		ob_start();
		
		?>

		<script>
			//var control_galleria_<? echo $this->att('id'); ?> = '';
			//control_galleria_<? echo $this->att('id'); ?>.load( data ) en json
			
			$(document).ready(function (){
				Galleria.loadTheme('<?php echo base_url($this->temas[$this->theme]['js']); ?>');
				$('#<?php echo $this->att('id'); ?>').css({height:'300px',width:'300px'});
				$('#<?php echo $this->att('id'); ?>').galleria({
					dataSource:	[<?php echo $elementos; ?>],
					autoplay: <?php echo $this->autoplay; ?>,
					debug:false,
					dummy:'<?php echo $this->dummy; ?>',
					transitionSpeed: <?php echo $this->transition_speed; ?>,
					transition:'<?php echo $this->transition; ?>',
					lightbox:true,
					imageCrop:'<?php echo $this->image_crop; ?>'
					<?php echo ','.$this->options; ?>
				});
				
			});
		</script>
		<?php

		$this->CI->dynamic_assets->add_code_js(ob_get_clean());
	}
}